/**
 * 请判断一个链表是否为回文链表
 * 示例一:
 *  输入: 1 -> 2
 *  输出: false
 * 示例二:
 *  输入: 1->2->2->1
 *  输出: true
*/
function Node (value) {
    this.value = value;
    this.next = null;
}
function palidromeLinkedList (node) {
    // 将链表转为正常数组判断
    const result = [];
    let curr = node;
    while (curr) {
        result.push(curr.value);
        curr = curr.next;
    }
    // 设置双指针向中间靠拢
    let start = 0;
    let end = result.length - 1;
    while (end > start) {
        // 如果由一个数不相等证明这个链表不是回文链表
        if (result[end] !== result[start]) {
            return false;
        }
        end--;
        start++;
    }
    return true;
}

const l1_1 = new Node(1);
const l1_2 = new Node(2);

l1_1.next = l1_2;

const l2_1 = new Node(1);
const l2_2 = new Node(2);
const l2_3 = new Node(2);
const l2_4 = new Node(1);
l2_1.next = l2_2;
l2_2.next = l2_3;
l2_3.next = l2_4;
console.log(palidromeLinkedList(l1_1));
console.log(palidromeLinkedList(l2_1));



